home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / snip9611.zip / FLOPCOPY.C < prev    next >
C/C++ Source or Header  |  1996-11-24  |  3KB  |  94 lines

  1. /* +++Date last modified: 02-Nov-1995 */
  2.  
  3. /*
  4. **  FLOPCOPY.C
  5. **
  6. **  Copy a floppy to a hard disk directory with directory recursion
  7. **  Public domain, uses functions from SNIPPETS.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include "sniptype.h"
  14. #include "dirport.h"
  15. #include "unistd.h"
  16. #include "snipfile.h"
  17.  
  18. void do_dir(char *, char *);
  19.  
  20. /*
  21. **  Copy a floppy to an HD subdirectory
  22. */
  23.  
  24. int main(int argc, char *argv[])
  25. {
  26.       char fdrv[4] = "A:\\", target[FILENAME_MAX];
  27.  
  28.       if (3 > argc)
  29.       {
  30.             puts("Usage: FLOPCOPY drive_letter subdir");
  31.             puts("where: drive_letter is \"A\" or \"B\" (colon optional)");
  32.             puts("       subdir is drive:dir target, e.g. \"C:\\FLOPSTUF\"");
  33.             return EXIT_FAILURE;
  34.       }
  35.       *fdrv = *argv[1];
  36.       strcpy(target, argv[2]);
  37.       if ('\\' != LAST_CHAR(target))
  38.             strcat(target, "\\");
  39.       
  40.       do_dir(fdrv, target);
  41.       return EXIT_SUCCESS;
  42. }
  43.  
  44. /*
  45. **  Process a directory (SNIPPETS: Treedir.C, modified)
  46. */
  47.  
  48. void do_dir(char *from, char *to)
  49. {
  50.       char search[FILENAME_MAX], new[FILENAME_MAX], newto[FILENAME_MAX];
  51.       DOSFileData ff;
  52.  
  53.       strcat(strcpy(search, from), "*.*");
  54.       if (Success_ == FIND_FIRST(to, _A_ANY, &ff))
  55.       {
  56.             if (0 == (ff_attr(&ff) & _A_SUBDIR))
  57.             {
  58.                   printf("*** %s Exists and is not a directory!\n", to);
  59.                   return;
  60.             }
  61.       }
  62.       else
  63.       {
  64.             strcpy(newto, to);
  65.             if ('\\' == LAST_CHAR(newto))
  66.                   LAST_CHAR(newto) = NUL;
  67.             mkdir(newto);
  68.       }
  69.       if (Success_ == FIND_FIRST(search, _A_ANY, &ff)) do
  70.       {
  71.             if (ff_attr(&ff) & _A_SUBDIR && '.' != *ff_name(&ff))
  72.             {
  73.                   strcat(strcat(strcpy(new, from), ff_name(&ff)), "\\");
  74.                   strcat(strcat(strcpy(newto, to), ff_name(&ff)), "\\");
  75.                   do_dir(new, newto);
  76.             }
  77.             else
  78.             {
  79.                   char file1[FILENAME_MAX], file2[FILENAME_MAX];
  80.  
  81.                   if ((ff_attr(&ff) & (_A_SUBDIR | _A_VOLID)) ||
  82.                         '.' == *ff_name(&ff))
  83.                   {
  84.                         continue;
  85.                   }
  86.                   strcat(strcpy(file1, from), ff_name(&ff));
  87.                   strcat(strcpy(file2, to), ff_name(&ff));
  88.                   if (Success_ != file_copy(file1, file2))
  89.                         printf("*** Unable to copy %s to %s\n", file1, file2);
  90.                   else  printf("Copied %s to %s\n", file1, file2);
  91.             }
  92.       } while (Success_ == FIND_NEXT(&ff));
  93. }
  94.